#include "widget.h"
#include "ui_widget.h"
#include <fstream>
#include <iostream>
#include <QDebug>
#include <string>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    std::ifstream file("D:/QtCode/qt-warehouse/Combo_2/config.txt");
    if(!file.is_open()){
        qDebug() << "打开文件失败！" ;
        return;
    }
    std::string str;
    while(std::getline(file,str)){
//        ui->comboBox->addItem(QString(str.c_str()));//QString 内部只能通过 char* 所以是使用c_str
        ui->comboBox->addItem(QString::fromStdString(str));//QString::fromStdString 将string装换成QString类型
    }

    file.close();//注意别忘了


    ui->comboBox_2->addItem("麦辣鸡腿堡");
    ui->comboBox_2->addItem("巨无霸");
    ui->comboBox_2->addItem("...");

    ui->comboBox_3->addItem("薯条");
    ui->comboBox_3->addItem("土豆泥");
    ui->comboBox_3->addItem("...");


    ui->comboBox_4->addItem("无糖可乐");
    ui->comboBox_4->addItem("雪碧");
    ui->comboBox_4->addItem("...");

    ui->spinBox->setRange(1,5);
    ui->spinBox_2->setRange(1,5);
    ui->spinBox_3->setRange(1,5);


}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{
    qDebug() << "汉堡：" << ui->comboBox_2->currentText() << " " << ui->spinBox->text();
    qDebug() << "小食：" << ui->comboBox_3->currentText() << " " << ui->spinBox_2->text();
    qDebug() << "饮料：" << ui->comboBox_4->currentText() << " " << ui->spinBox_3->text();
}
